<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>DingDing Admin</title>
    <div th:include="includeJs::bootstrap_js"></div>
    <div th:include="includeJs::layui_js"></div>
</head>
<div class="container-scroller d-flex">
    <div th:replace="includeJs::admin_leftNav"></div>
    <div class="container-fluid page-body-wrapper">
        <div th:replace="includeJs::admin_nav"></div>
        <div class="main-panel" style="height: 800px;">
            <script type="text/html" id="top">
                <label  class="layui-form-item">
                    <label class="layui-form-label" style="width: 90px;">借贷类型:</label>
                    <div class="layui-input-inline">
                        <select id="status"  name="status" lay-verify="required">
                            <option value="0">--未选择--</option>
                            <option th:each="t:${dType}" th:text="${t.type}" th:value="${t.TId}" >启用</option>
                        </select>
                    </div>
                    <label class="layui-form-label">期限:</label>
                    <div class="layui-input-inline">
                        <select id="month"  name="month" lay-verify="required">
                            <option value="0">--未选择--</option>
                            <option  value="1" >1-3月</option>
                            <option  value="2" >4-6月</option>
                            <option  value="3" >6-12月</option>
                            <option  value="4" >12月及以上</option>
                        </select>
                    </div>
                    <label class="layui-form-label">年利率</label>
                    <div class="layui-input-inline">
                        <select id="yearInterset"  name="yearInterset" lay-verify="required">
                            <option value="0">--未选择--</option>
                            <option  value="1" >12%以下</option>
                            <option  value="2" >12%-14%</option>
                            <option  value="3" >14%-16%</option>
                            <option  value="4" >16%以上</option>
                        </select>
                    </div>
                    <label class="layui-form-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                    <label class="layui-form-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                    <label class="layui-form-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                    <label class="layui-form-label" style="width: 90px;">审核状态</label>
                    <div class="layui-input-inline">
                        <select id="order_state"  name="order_state" lay-verify="required">
                            <option value="100">--未选择--</option>
                            <option  value="6" >订单取消</option>
                            <option  value="0" >未通过</option>
                            <option  value="1" >审核中</option>
                            <option  value="2" >审核通过</option>
                            <option  value="3" >放款中</option>
                            <option  value="4" >已放款</option>
                            <option  value="5" >已还清</option>
                        </select>
                    </div>
                    <label class="layui-form-label" style="width: 90px">申请人:</label>
                    <div class="layui-input-inline">
                        <input class="layui-input"  maxlength="15" id="username" value=""/>
                    </div>
                    <div class="layui-input-inline">
                        <button id="seek" type="submit" class="layui-btn" onclick="seek()">搜索</button>
                    </div>
                    </label>
            </script>
            <table class="layui-hide" lay-filter="test" id="demo"></table>
            <script type="text/html" id="barDemo">
                <button class="layui-btn layui-btn-sm" lay-event="edit" >审核</button>
            </script>
        </div>
    </div>
</div>
<script type="text/javascript">
    let layer;
    let table;
    layui.use(['table', 'layer'], function(){
        layer = layui.layer;
        table = layui.table;
        table.render({
            elem: '#demo'
            ,height: 700
            ,method:'post'
            ,url: '/admin/auditList' //数据接口
            ,page: true //开启分页
            ,id:"clientId"
            ,toolbar: '#top' //开启头部工具栏，并为其绑定左侧模板
            ,cols: [
                [ //表头
                     {field: 'l_id', title: '编号', width:80, sort: true, fixed: 'left'}
                    ,{field: 'real_name', title: '申请人', width:100}
                    ,{field: 'order_time', title: '申请时间', width:190,templet : "<div>{{layui.util.toDateString(d.order_time, 'yyyy年MM月dd日 HH:mm')}}</div>"}
                    ,{field: 'l_money', title: '借款金额', width:120,sort: true}
                    ,{field: 'l_month', title: '借款期限(月)',sort: true, width:120,sort: true}
                    ,{field: 'l_phone', title: '手机号', width:115}
                    ,{field: 'identity_card', title: '身份证号', width:150}
                    //,{field: 'age', title: '年龄', width: 120}
                    //,{field: 'oname', title: '职业', width: 115}
                    ,{field: 'monthly_profit', title: '月收入', width:100}
                    ,{field: 'company', title: '所在公司名称', width: 100}
                    //,{field: 'Company_phone', title: '公司电话', width: 80}
                    //,{field: 'address', title: '住址', width: 100}
                    //,{field: 'street', title: '街道', width: 100}
                    //,{field: 'gname', title: '担保方式',width: 100}
                    //,{field: 'item_value', title: '抵押物品价值(万)',width: 100}
                    ,{field: 'purpose_of_loan', title: '借款用途',width: 100}
                    ,{field: 'interest_rate', title: '年利率',width: 100}
                    ,{field: 'Month_money', title: '每月还款金额',width: 100}
                    ,{field: 'comment_of_loan', title: '借款描述',width: 100}
                    ,{field: 'type', title: '贷款类型',width: 100}
                    ,{field: 'audit_time', title: '审核时间',width: 200}
                    ,{field: 'loan_time', title: '放款时间',width: 200}
                    ,{field: 'audit_comment', title: '审核备注',width: 100}
                    ,{field: 'order_state', title: '审核状态',width: 100}
                    ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
                ]
            ]
            ,page: {limit:10,page:1,limits:[10,30,50,100],layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']}
            ,done: function(res, page, count){
                //年利率
                $("[data-field='interest_rate']").children().each(function(){
                    let data = $(this).text();
                    if(!isNaN(data)){
                        data = data+" %"
                        $(this).text(data);
                    }
                })
                //订单状态
                $("[data-field='order_state']").children().each(function(){
                    let data = $(this).text();
                    //不通过
                    if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_NO_PASS}]]){
                        $(this).text('未通过');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_AUDIT}]]){
                        $(this).text('审核中');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_PASS}]]){
                        $(this).text('审核通过');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_LOAN_ING}]]){
                        $(this).text('放款中');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_LOAN_SUCCESS}]]){
                        $(this).text('已放款');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_EMPTY}]]){
                        $(this).text('已还清');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).NLOAN_ORDER_STATE_CACEL}]]){
                        $(this).text('用户取消');
                    }
                })
                //审核时间
                $("[data-field='audit_time']").children().each(function(){
                    let data = $(this).text();
                    if(data.length==29){
                        let auditTime = layui.util.toDateString(data, 'yyyy年MM月dd日 HH:mm:ss')
                        $(this).text(auditTime)
                    }
                })

                //放款时间
                $("[data-field='loan_time']").children().each(function(){
                    let data = $(this).text();
                    if(data.length==29){
                        let auditTime = layui.util.toDateString(data, 'yyyy年MM月dd日 HH:mm:ss')
                        $(this).text(auditTime)
                    }
                })
            }
        })
        //监听工具条
        table.on('tool(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            let data = obj.data; //获得当前行数据
            let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            let tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'edit'){ //审核
                //同步更新缓存对应的值
                /*obj.update({
                    username: '123'
                    ,title: 'xxx'
                });*/window.location.href="/admin/audit/"+data.l_id;
            }})
    });
    function seek() {
        let status = $("#status").val();
        let month = $("#month").val();
        let yearInterset = $("#yearInterset").val();
        let order_state = $("#order_state").val();
        let username = $("#username").val();

        //console.log(status)
        //console.log(month)
        //console.log(yearInterset)
        //console.log(order_state)
        //console.log(username)

        //layer.alert("部门id"+empId+"员工姓名"+empName+"手机号"+Phone+"状态"+status);
        table.reload('clientId',{
            url:'/admin/audit/seek',
            where:{
                status:status,
                month:month,
                yearInterset:yearInterset,
                order_state:order_state,
                username:username
            }
            ,page: {limit:10,page:1,limits:[10,30,50,100],layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']}
            ,done: function(res, page, count){
                //年利率
                $("[data-field='interest_rate']").children().each(function(){
                    let data = $(this).text();
                    if(!isNaN(data)){
                        data = data+" %"
                        $(this).text(data);
                    }
                })
                //订单状态
                $("[data-field='order_state']").children().each(function(){
                    let data = $(this).text();
                    //不通过
                    if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_NO_PASS}]]){
                        $(this).text('未通过');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_AUDIT}]]){
                        $(this).text('审核中');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_PASS}]]){
                        $(this).text('审核通过');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_LOAN_ING}]]){
                        $(this).text('放款中');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_LOAN_SUCCESS}]]){
                        $(this).text('已放款');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).LOAN_ORDER_STATE_EMPTY}]]){
                        $(this).text('已还清');
                    }else if(data==[[${T(com.ddf.publics.tool.Constant).NLOAN_ORDER_STATE_CACEL}]]){
                        $(this).text('用户取消');
                    }
                })
            }
        })
        //搜索完把值传回去
        $("#status").val(status);
        $("#month").val(month);
        $("#yearInterset").val(yearInterset);
        $("#order_state").val(order_state);
        $("#username").val(username);
    }
</script>
</body>
</html>